import {cdnBase, config} from '../../config/index';

/** 获取首页数据 */
function mockFetchHome() {
  const { delay } = require('../_utils/delay');
  const { genSwiperImageList } = require('../../model/swiper');
  return delay().then(() => {
    return {
      swiper: genSwiperImageList(),
      tabList: [
        {
          text: '精选推荐',
          key: 0,
        },
        {
          text: '夏日防晒',
          key: 1,
        },
        {
          text: '二胎大作战',
          key: 2,
        },
        {
          text: '人气榜',
          key: 3,
        },
        {
          text: '好评榜',
          key: 4,
        },
        {
          text: 'RTX 30',
          key: 5,
        },
        {
          text: '手机也疯狂',
          key: 6,
        },
      ],
      activityImg: `${cdnBase}/activity/banner.png`,
    };
  });
}

/** 获取首页数据 */
export function fetchHome() {
  if (config.useMock) {
    return mockFetchHome();
  }
  return new Promise((resolve) => {
    resolve('real api');
  });
}
// 获取轮播图
export  function getSwiper() {
  const db = wx.cloud.database()
  const swipers = db.collection('home-header-carousel')
  return new Promise((resolve, reject) => {
    swipers.get({
      success: function(res) {
        console.log({res})
        resolve(res.data)
      },
    })
  })
}

export  function getNavTabList() {
  const db = wx.cloud.database()
  return new Promise((resolve, reject) => {
    db.collection('home-nav-tabs').get({
      success: (res) => {
        resolve(res.data)
      },
    })
  })
}


export  function  getBusinessTypes() {
  const db = wx.cloud.database()
  return new Promise((resolve, reject) => {
    db.collection('home-business-types').get({
      success: (res) => {
        resolve(res.data)
      },
    })
  })
}
// 获取医院
export  function  getHospitalList(hospitalId) {
    const db = wx.cloud.database()
  console.log("getHospitalList")
    return new Promise((resolve, reject) => {
        db.collection('hospital').get({
            success: (res) => {
                resolve(res.data)
            },
        })
    })
}